import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param input int整型一维数组 
     * @param k int整型 
     * @return int整型ArrayList
     */
    public ArrayList<Integer> GetLeastNumbers_Solution (int[] input, int k) {
        // write code here
        // 大根堆
        PriorityQueue<Integer> bigHeap = new PriorityQueue<>((num1, num2) -> num2 - num1);

        for (int i = 0; i < k; i++) {
            bigHeap.offer(input[i]);
        }
        for (int i = k; i < input.length; i++) {
            if (input[i] < bigHeap.peek()) {
                bigHeap.poll();
                bigHeap.offer(input[i]);
            }
        }

        ArrayList<Integer> ret = new ArrayList<>();
        while (!bigHeap.isEmpty()) {
            ret.add(bigHeap.poll());
        }

        return ret;
    }
}